


macro(SetCrossCompiler)
    enable_language(C ASM CXX)
    set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
    SET(CMAKE_SYSTEM_NAME Generic)
    SET(CMAKE_SYSTEM_PROCESSOR arm)
    SET(CMAKE_CROSSCOMPILING 1)
    set(CMAKE_C_COMPILER_WORKS 1)
    include(CMakeForceCompiler)
    set(TOOLCHAIN_DIR /home/ysbf/Application/gcc-arm-none-eabi-9-2020-q2-update)
    set(TOOLCHAIN_BIN_DIR ${TOOLCHAIN_DIR}/bin)
    set(TOOLCHAIN_INC_DIR ${TOOLCHAIN_DIR}/lib/arm-none-eabi/include)
    set(TOOLCHAIN_LIB_DIR ${TOOLCHAIN_DIR}/lib/arm-none-eabi/lib)
    set(CMAKE_ASM_COMPILER ${TOOLCHAIN_DIR}/bin/arm-none-eabi-gcc)
    set(CMAKE_C_COMPILER ${TOOLCHAIN_DIR}/bin/arm-none-eabi-gcc)
    set(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/bin/arm-none-eabi-g++)
    set(CMAKE_OBJCOPY arm-none-eabi-objcopy)
    set(CMAKE_AR arm-none-eabi-ar)
    set(CMAKE_RANLIB arm-none-eabi-ranlib)
    set(CMAKE_OBJDUMP arm-none-eabi-objdump)
    set(CMAKE_SIZE arm-none-eabi-size)
    set(MCU_FLAGS " -mcpu=cortex-m4 -mthumb  -mfloat-abi=hard -mfpu=fpv4-sp-d16 ")
    #        set(ASM_FILE "./startup_stm32f40_41xxx.s")
    #        set_property(SOURCE ${ASM_FILE} PROPERTY LANGUAGE C)
    set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32F417IGHx_FLASH.ld)
    set(CMAKE_EXE_LINKER_FLAGS " ${MCU_FLAGS} -specs=nano.specs -specs=nosys.specs -u _sprintf_float  -u _scanf_float -u _printf_float -T${LINKER_SCRIPT} -Wl,--gc-sections ")
    #-fexceptions -frtti  -lm
    #rdimon.specs

    set(COMMON_FLAGS " -Wall -Wextra -Wshadow   -Werror=return-type  -Wdouble-promotion  -Wno-multichar -Wno-unused-parameter -Wno-unused-function -Wno-unused-label " )


    set(CMAKE_C_FLAGS " ${MCU_FLAGS}   -O0 -ffunction-sections -fdata-sections  -ggdb3   -ffast-math  -fno-common -fsigned-char -fmessage-length=0 ${COMMON_FLAGS} ")
    set(CMAKE_C_FLAGS_DEBUG "-O0 -g2 -ggdb")
    set(CMAKE_C_FLAGS_RELEASE "-O3")
    #    set(CMAKE_CXX_FLAGS " ${MCU_FLAGS}  -lstdc++  -ffast-math   -Wall  -ffunction-sections -fdata-sections -fno-unroll-loops  -g -ggdb3 -fno-exceptions -fverbose-asm -fdata-sections -ffunction-sections -Wno-psabi ")  # -fpermissive

    set(CMAKE_CXX_FLAGS " ${MCU_FLAGS}   -lstdc++  -ffast-math   -O0   -Wall  -ffunction-sections -fdata-sections -fno-unroll-loops  -ggdb3 -fno-exceptions -fverbose-asm -fdata-sections -ffunction-sections -Wno-psabi ${COMMON_FLAGS}  ")  # -fpermissive
    set(CMAKE_ASM_FLAGS "${MCU_FLAGS} -D__ASSEMBLY__ -Os -ffunction-sections -fdata-sections  -ggdb3  -fno-common -fsigned-char -fmessage-length=0  -Wall -Wextra -Wshadow ")
endmacro()
